package com.ruoyi.facilities.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.facilities.domain.Facilities;
import com.ruoyi.facilities.service.IFacilitiesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公寓配套设施管理Controller
 *
 * @author ruoyi
 * @date 2024-10-10
 */
@RestController
@RequestMapping("/facilities/facilities")
public class FacilitiesController extends BaseController
{
    @Autowired
    private IFacilitiesService facilitiesService;

    /**
     * 查询公寓配套设施管理列表
     */
    @PreAuthorize("@ss.hasPermi('facilities:facilities:list')")
    @GetMapping("/list")
    public TableDataInfo list(Facilities facilities)
    {
        startPage();
        List<Facilities> list = facilitiesService.selectFacilitiesList(facilities);
        return getDataTable(list);
    }

    /**
     * 导出公寓配套设施管理列表
     */
    @PreAuthorize("@ss.hasPermi('facilities:facilities:export')")
    @Log(title = "公寓配套设施管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Facilities facilities)
    {
        List<Facilities> list = facilitiesService.selectFacilitiesList(facilities);
        ExcelUtil<Facilities> util = new ExcelUtil<Facilities>(Facilities.class);
        util.exportExcel(response, list, "公寓配套设施管理数据");
    }

    /**
     * 获取公寓配套设施管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('facilities:facilities:query')")
    @GetMapping(value = "/{facilityId}")
    public AjaxResult getInfo(@PathVariable("facilityId") Long facilityId)
    {
        return success(facilitiesService.selectFacilitiesByFacilityId(facilityId));
    }
    /*根据设备id获取设施名称*/
    @GetMapping("/getFacilityNameById/{facilityId}")
    public AjaxResult getFacilityNameById(@PathVariable("facilityId") Long facilityId)
    {
        return success(facilitiesService.selectFacilitiesByFacilityId(facilityId));
    }


    /**
     * 新增公寓配套设施管理
     */
    @PreAuthorize("@ss.hasPermi('facilities:facilities:add')")
    @Log(title = "公寓配套设施管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Facilities facilities)
    {
        return toAjax(facilitiesService.insertFacilities(facilities));
    }

    /**
     * 修改公寓配套设施管理
     */
    @PreAuthorize("@ss.hasPermi('facilities:facilities:edit')")
    @Log(title = "公寓配套设施管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Facilities facilities)
    {
        return toAjax(facilitiesService.updateFacilities(facilities));
    }

    /**
     * 删除公寓配套设施管理
     */
    @PreAuthorize("@ss.hasPermi('facilities:facilities:remove')")
    @Log(title = "公寓配套设施管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{facilityIds}")
    public AjaxResult remove(@PathVariable Long[] facilityIds)
    {
        return toAjax(facilitiesService.deleteFacilitiesByFacilityIds(facilityIds));
    }

}
